"""通用工具模块 - 提供其他通用功能。"""

from typing import Any, Dict, Optional
from dotenv import find_dotenv, load_dotenv

# 加载环境变量
_: bool = load_dotenv(find_dotenv())


def safe_get_config_value(config: Dict[str, Any], key: str, default: Any = None) -> Any:
    """Safely get a value from config dictionary.
    
    Args:
        config: Configuration dictionary
        key: Key to retrieve
        default: Default value if key not found
        
    Returns:
        The value from config or default
    """
    return config.get(key, default)


def format_error_message(error: Exception, context: str = "") -> str:
    """Format error message with context.
    
    Args:
        error: The exception that occurred
        context: Additional context information
        
    Returns:
        Formatted error message
    """
    if context:
        return f"Error in {context}: {str(error)}"
    return f"Error: {str(error)}"